package com.weaver.drools.business.execution.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.weaver.drools.business.execution.service.IDWrit100Service;
import com.weaver.drools.common.dao.DWrit100Dao;
import com.weaver.drools.common.entity.DWrit100;
@Service
public class DWrit100ServiceImpl implements IDWrit100Service {
	
	@Autowired
	private DWrit100Dao writ100Dao;
	
	@Override
	public DWrit100 findById(Long writid) {
		// TODO Auto-generated method stub
		return writ100Dao.findDWrit100ByWritid(writid);
	}

	@Override
	public void saveDWrit100(DWrit100 writ100) {
		writ100Dao.saveOrUpdate(writ100);

	}

	@Override
	public void updateDWrit100(DWrit100 writ100) {
		writ100Dao.saveOrUpdate(writ100);
	}

	@Override
	public void deleteById(Long writid) {
		writ100Dao.deleteById(writid);

	}

	@Override
	public DWrit100 findLastWritBean(Long writTypeId, Long unitId, String year, Long isCoordinator) throws Exception {
		DWrit100 writBean=new DWrit100();
		String hql="from DWrit100 where isdeleted=0";
		if(writTypeId!=null){
			hql+=" and DWrittype99.writtypeid = "+writTypeId;
		}
		if(unitId!=null){
			hql+=" and QCmnUnit18.unitid = "+unitId;
		}
		if(year!=null && !year.equals("")){
			hql+=" and year = '"+year+"'";
		}
		if(isCoordinator!=null){
			hql+=" and iscoordinator = "+isCoordinator;
		}
		hql+=" order by writid desc";
		List<DWrit100> writList=writ100Dao.findListByhql(hql);
		if(writList.size()!=0){
			writBean=writList.get(0);
		}
		return writBean;
	}

}
